package com.heima.media.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.common.dto.PageResponseResult;
import com.heima.common.dto.ResponseResult;
import com.heima.media.Mapper.WmChannelMapper;
import com.heima.media.entity.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
@Service
public class IWmChannelServiceImpl extends ServiceImpl<WmChannelMapper, WmChannel> implements IWmChannelService {

    @Override
    public ResponseResult listByName(ChannelDto dto) {
        //开启分页 构建条件
        IPage<WmChannel> page = new Page<>(dto.getPage(),dto.getSize());
        LambdaQueryWrapper<WmChannel> queryWrapper = new LambdaQueryWrapper<>();

        if ( !StringUtils.isEmpty(dto.getName())){
            queryWrapper.like(WmChannel::getName,dto.getName());
        }
        IPage<WmChannel> iPage = this.page(page, queryWrapper);
        long total = iPage.getTotal();
        List<WmChannel> list = iPage.getRecords();
        PageResponseResult pageResponseResult = new PageResponseResult (dto.getPage(), dto.getSize(), total, list);
        return pageResponseResult;
    }


}
